package com.community.itelligentcommunity.sys.controller;

import com.community.itelligentcommunity.common.base.constant.SystemStaticConst;
import com.community.itelligentcommunity.common.base.controller.GenericController;
import com.community.itelligentcommunity.common.base.service.GenericService;
import com.community.itelligentcommunity.sys.entity.QueryUserRole;
import com.community.itelligentcommunity.sys.entity.UserRole;
import com.community.itelligentcommunity.sys.service.RoleService;
import com.community.itelligentcommunity.sys.vo.UserRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述：角色管理controller类
 */
@Controller
@RequestMapping("/role")
public class RoleController extends GenericController<UserRole,QueryUserRole> {

    @Autowired
    private RoleService roleService;

    @Override
    protected GenericService<UserRole, QueryUserRole> getService() {
        return roleService;
    }

    /**
     * 功能描述：更新角色数据成功
     * @param entity
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateUserRole",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> updateUserRole(UserRoleVo entity)  throws Exception{
        boolean success  = roleService.updateUserRole(entity);
        Map<String,Object> result = new HashMap<String, Object>();
        if(success==true){
            result.put(SystemStaticConst.RESULT,SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"更新角色成功！");
            result.put("entity",entity);
        }else{
            result.put(SystemStaticConst.RESULT,SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"更新角色失败！");
        }
        return result;
    }

    /**
     * 功能描述：保存角色数据
     * @param entity
     * @return
     */
    @RequestMapping(value = "/saveUserRole",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> saveUserRole(UserRoleVo entity) throws Exception{
        boolean success = roleService.saveUserRole(entity);
        Map<String,Object> result = new HashMap<String, Object>();
        if(success==true){
            result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"增加角色成功！");
            result.put("entity",entity);
        }else{
            result.put(SystemStaticConst.RESULT,SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"增加角色失败！");
        }
        return result;
    }

}
